#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <string.h>
int main(int argc, char **argv)
{
    struct in_addr client_ip;
    struct sockaddr_in server_addr;
    struct sockaddr_in client_addr;
    char buffer[1024];
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(8888);
    inet_pton(AF_INET, "192.168.100.128", &server_addr.sin_addr);
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        perror("socket create failed!\n");
        exit(1);
    }
    printf("socket create Success! %d\n", sockfd);
    socklen_t addrlen = sizeof(server_addr);
    connect(sockfd, (struct sockaddr *)&server_addr, addrlen);
    int fd = open("a.txt", O_RDWR | O_CREAT , 0655);
    ssize_t size;
    while ((size = read(fd, buffer, sizeof(buffer))) > 0)
    {
        send(sockfd, buffer, sizeof(buffer), 0);
        memset(buffer, 0, sizeof(buffer));
    }
    send(sockfd, "Hello", strlen("Hello"), 0);

    int len = recv(sockfd, buffer, sizeof(buffer) - 1, 0);
    if (len < 0)
    {
        perror("read client message error!");
        exit(1);
    }
    buffer[len] = '\0';
    printf("recv: %s\n", buffer);
    close(sockfd);
    return 0;
}